package cn.lanqiao.daoimpl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import cn.lanqiao.dao.CommonHeroDao;
import cn.lanqiao.dao.UserDao;
import cn.lanqiao.entity.CommonHero;
import cn.lanqiao.util.JdbcUtil;

public class CommonHeroDaoImpl implements CommonHeroDao {
	CommonHero commonHero = null;
	UserDao user = new UserDaoImpl();
	private static Connection conn = null;
	static
	{
		conn = JdbcUtil.getConnection(); //与数据库建立连接
	}
	@Override
	public List getCommonHero() {
		List list = new ArrayList();
		String sql = "select * from K_COMMONHERO where id=?"; //获取数据库数据的SQL语句
		try {
			PreparedStatement ps = conn.prepareStatement(sql); //获取Statement对象
			String id ="1001";
			ps.setString(1,id);
			ResultSet rs = ps.executeQuery();  //执行Statement对象，返回结果集
			while(rs.next()) {
				String commonName = rs.getString("COMHERO"); //分别取出数据
				String commonHeroUsenum = rs.getString("USENUM");
				commonHero = new CommonHero(id, commonName, commonHeroUsenum);
				list.add(commonHero);
			}
			JdbcUtil.close(rs, ps, conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
	}
		Iterator it = list.iterator();
		while(it.hasNext()) {
			CommonHero commonHeroList = (CommonHero) it.next();
	}
		return list;
  }
}
